﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace memcached
{
    /// <summary>
    /// Transform keys within a region into unique keys.
    /// </summary>
    /// <remarks>Useful to provide different cache namespace for each application/area.</remarks>
    public class RegionTransformer : Enyim.Caching.Memcached.IMemcachedKeyTransformer
    {
        /// <summary>
        /// New instance.
        /// </summary>
        public RegionTransformer()
        {
        }

        /// <summary>
        /// New instance.
        /// </summary>
        /// <param name="regionCode"></param>
        public RegionTransformer(string regionCode)
        {
            RegionCode = regionCode;
        }

        /// <summary>
        /// Code of region.
        /// </summary>
        public string RegionCode { get; set; }

        /// <summary>
        /// Performs the transformation.
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public string Transform(string key)
        {
            return string.Concat(RegionCode, ":", key);
        }
    }
}